/**
 * create by young (young2f@outlook.com) on 2020/9/12
 */


'use strict';
import React from 'react';
import {connect} from 'dva/index';
import {DatePicker, Form, Select} from 'antd';
import styles from '../index.less';
import FormBase from '../../components/Base/FormBase';
import moment from 'moment';
import 'moment/locale/zh-cn';
import DirTree from "../../components/DirTree";
import ReceiptDataFace from "./dataFace/ReceiptDataFace";

moment.locale('zh-cn');
const {RangePicker} = DatePicker;
const _ = require('lodash');

const table = 'receipt';
const title = '收入记录表';
const {Option} = Select;
@Form.create()
@connect(({
            user,
            global,
            treeNode,
            procure,
            finance
          }) => ({...user, ...global, ...procure, ...finance, ...treeNode}))
export default class ReceiptTree extends FormBase {
  constructor(props) {
    super(props);
    this.state = {};
  }

  componentDidMount() {
    const {dispatch} = this.props;
    this.setState({});

  }

  onTreeNodeSelected = (node) => {
    if (!node) return;
    this.state.treeNode = node;
    this.componentDidMount();
  };
//todo
  onTreeDelete = (_id, result) => {

  };

  dataPage() {
    const {treeNode = {}} = this.state;
    const {treeId, name, rootName} = treeNode;
    // if (treeId === 'TRESALESRECEIPT') {
    //   return <SalesReceiptDataFace
    //     treeId={treeId}
    //     title={name}
    //   ></SalesReceiptDataFace>;
    // }

    // this.props.dispatch({
    //   type: 'finance/findRecordMany',
    //   payload: {treeId}
    // });

    return <ReceiptDataFace
      treeId={treeId}
      treeName={name}
      treeNode={treeNode}
    ></ReceiptDataFace>;
  }

  render() {
    const {dispatch, _notify, expandedKeys} = this.props;


    return (
      <Form className={styles.content}>
        <DirTree
          width={"19%"}
          disableEdit={false}
          table={table}
          dispatch={dispatch}
          onTreeDelete={this.onTreeDelete}
          onTreeNodeSelected={this.onTreeNodeSelected}
          expandedKeys={expandedKeys}
          defaultExpandAll={true}
          title={title}
        > {this.dataPage()}</DirTree>
      </Form>
    );
  }
}
